package com.gadgets.framework.common.util;

import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;

/**
 * @author UncleXiu
 * @version V1.0.0
 * @data 2020-12-11
 *
 */
public class ExcelExportUtil {

    /**
     * 获取Excel文件输出流
     * @param fileName  文件名
     * @return  文件输出流
     */
    public static OutputStream getExcelOutputStream(String fileName,String path) throws IOException {
        File excelFile = new File(path, fileName+".xlsx");
        if(!excelFile.exists()){
            excelFile.createNewFile();
        }
        return FileOperUtil.getOutputStream(excelFile);
    }

    /**
     * 获取Excel导出对象
     * @return      导出对象
     */
    public static Workbook getExcelBookObject(List<String> sheetName){
        Workbook book = new XSSFWorkbook();
        for (String s : sheetName) {
            book.createSheet(s);
        }
        return book;
    }

}
